package testingtool.arrays;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class ArraysTest
{
    public static void main( String[] args )
    {

        Integer[] arr = { 1, 2, 3, 4 };
        
        List<Integer> list = Arrays.asList( arr );

        System.out.println( convertListToString( list, "," ) );
    }

    public static <T> String convertListToString( Collection<T> collection, String splitter )
    {
        StringBuilder strBuilder = new StringBuilder();
        Iterator<T> itr = collection.iterator();

        while( itr.hasNext() )
        {
            T element = itr.next();
            strBuilder.append( element );
            if( itr.hasNext() )
            {
                strBuilder.append( splitter );
            }
        }

        return strBuilder.toString();
    }
}
